package com.yami.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.model.Cyclopedia;
import com.yami.shop.common.util.RedisUtil;
import com.yami.shop.dao.CyclopediaMapper;
import com.yami.shop.service.CyclopediaService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
@Slf4j
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
public class CyclopediaServiceImpl extends ServiceImpl<CyclopediaMapper, Cyclopedia> implements CyclopediaService {

    @Autowired
    private CyclopediaMapper cyclopediaMapper;

    @Override
    @Cacheable(cacheNames = "cyclopedia", key = "#cyclopediaId")
    public Cyclopedia getCyclopediaById(Long cyclopediaId) {
        return cyclopediaMapper.selectById(cyclopediaId);
    }

    @Override
    @CacheEvict(cacheNames = "notices", key = "#cyclopediaId")
    public void removeCyclopediaCacheById(long cyclopediaId) {
        RedisUtil.del("cyclopedia::"+cyclopediaId);
    }
}
